const { By, until } = require('selenium-webdriver')

module.exports = function getComment (driver, appid) {
  const target = By.css('.comment-statistics .score-star .num')
  const loadingEle = By.css('.router-loading')
  return driver.get(`https://www.qimai.cn/app/comment/appid/${appid}/country/cn`)
  .then(() => {
    return driver.sleep(4000)
  })
  .then(() => {
    return driver.findElements(target)
  })
  .then((scores) => {
    const scoreTasks = []
    scores.forEach((score) => {
      scoreTasks.push(score.getText())
    })
    return Promise.all(scoreTasks)
  })
  .then(([currentScore, allScore]) => {
    return {
      currentScore,
      allScore
    }
  })
}